<?php
class Muserimg extends CI_Model{
	function __construct(){
		parent::__construct();
	}
	function getUserImg(){
		$arr = array();
		$sql = "select * from tbuserimg where id = 1";
		$query = $this->db->query($sql);
		foreach ($query->result() as $row){
			$arr["id"] = $row->id;
			$arr["sh"] = $row->sh;
			$arr["shurl"] = $row->shurl;
			$arr["shisvalid"] = $row->shisvalid;
			$arr["mt"] = $row->mt;
			$arr["mturl"] = $row->mturl;
			$arr["mtisvalid"] = $row->mtisvalid;
			$arr["sy"] = $row->sy;
			$arr["syurl"] = $row->syurl;
			$arr["syisvalid"] = $row->syisvalid;
			$arr["hy"] = $row->hy;
			$arr["hyurl"] = $row->hyurl;
			$arr["hyisvalid"] = $row->hyisvalid;
			$arr["rz"] = $row->rz;
			$arr["rzurl"] = $row->rzurl;
			$arr["rzisvalid"] = $row->rzisvalid;
		}
		return $arr;
	}

    /**
     * 获取图标
     * @return mixed
     */
    function getUserIcon()
    {
        $sql = "select * from tbuserimg";
        $query = $this->db->query($sql);
        $data = $query->row_array();
        $sh['name'] = isset($data['sh']) ? $data['sh'] : 0;
        $sh['url'] = isset($data['shurl']) ? $data['shurl'] : 0;
        $sh['status'] = isset($data['shisvalid']) ? $data['shisvalid'] : 0;
        $mt['name'] = isset($data['mt']) ? $data['mt'] : 0;
        $mt['url'] = isset($data['mturl']) ? $data['mturl'] : 0;
        $mt['status'] = isset($data['mtisvalid']) ? $data['mtisvalid'] : 0;
        $sy['name'] = isset($data['sy']) ? $data['sy'] : 0;
        $sy['url'] = isset($data['syurl']) ? $data['syurl'] : 0;
        $sy['status'] = isset($data['syisvalid']) ? $data['syisvalid'] : 0;
        $hy['name'] = isset($data['hy']) ? $data['hy'] : 0;
        $hy['url'] = isset($data['hyurl']) ? $data['hyurl'] : 0;
        $hy['status'] = isset($data['hyisvalid']) ? $data['hyisvalid'] : 0;
        $rz['name'] = isset($data['rz']) ? $data['rz'] : 0;
        $rz['url'] = isset($data['rzurl']) ? $data['rzurl'] : 0;
        $rz['status'] = isset($data['rzisvalid']) ? $data['rzisvalid'] : 0;
        return $item = array($sh,$mt,$sy,$hy,$rz);
    }






	function setUserImg($sh,$shisvalid,$mt,$mtisvalid,$sy,$syisvalid,$hy,$hyisvalid,$rz,$rzisvalid){
		
		$sql = "update tbuserimg set sh = ?,shisvalid = ?,mt = ?,mtisvalid = ?,
								sy = ?,syisvalid = ?,hy = ?,hyisvalid = ?,rz = ?,rzisvalid = ?
								where id = 1";
		$this->db->query($sql,array("$sh","$shisvalid","$mt","$mtisvalid","$sy","$syisvalid","$hy","$hyisvalid","$rz","$rzisvalid"));
	}




	function saveUserImg($type,$url){
		$this->initUserImg();
		$sql="";
		if($type=="1"){
			$sql = "update tbuserimg set shurl = ? where id = 1";
		}else if($type=="2"){
			$sql = "update tbuserimg set mturl = ? where id = 1";
		}else if($type=="3"){
			$sql = "update tbuserimg set syurl = ? where id = 1";
		}else if($type=="4"){
			$sql = "update tbuserimg set hyurl = ? where id = 1";
		}else if($type=="5"){
			$sql = "update tbuserimg set rzurl = ? where id = 1";
		}
		
		if($sql!=""){
			$this->db->query($sql,array("$url"));
		}
	}
	function initUserImg(){
		$sql = "select * from tbuserimg where id = 1";
		$query = $this->db->query($sql);
		$exists = false;
		foreach ($query->result() as $row){
			$exists = true;
		}
		if($exists == false){
			$sql = "insert into tbuserimg(id) values(1)";
			$this->db->query($sql);
		}
	}
}
?>